import request from "@/utils/request";
import axios from "axios";
import { getToken } from "@/utils/auth";
import host from "@/utils/host";

let token = getToken();

export default {
  getAll(data) {
    return request({
      url: `/subject/getAllR3`,
      method: "get",
    });
  },
  getAllSubject() {
    return request({
      url: `/subject/getAllSubject`,
      method: "get",
    });
  },
  /**
   * 获取满足vant要求的数据结构
   * options: [
        {
          text: '浙江省',
          value: '330000',
          children: [{ text: '杭州市', value: '330100' }],
        },
        {
          text: '江苏省',
          value: '320000',
          children: [{ text: '南京市', value: '320100' }],
        },
      ],
   * @returns
   */
  getTree() {
    return request({
      url: `/subject/getTree`,
      method: "get",
    });
  },

  getAllTree() {
    return request({
      url: `/subject/getAllTreeElementUI`,
      method: "get",
    });
  },

  // getBySubjectId(subjectId) {
  //   return request({
  //     url: `/subject/getBySubjectId/${subjectId}`,
  //     method: "get",
  //   });
  // },

  getZhizhaoLeafs() {
    return request({
      url: `/subject/getZhizhaoLeafs`,
      method: "get",
    });
  },

  getLeafs() {
    return request({
      url: `/subject/getLeafs`,
      method: "get",
    });
  },

  getById(id) {
    return request({
      url: `/subject/getById/${id}`,
      method: "get",
    });
  },

  getByName(name) {
    return request({
      url: `/subject/getByName/${name}`,
      method: "get",
    });
  },

  update(data, oldStudents) {
    const str = JSON.stringify(data.ppts);
    data.ppts = str;
    data.videos = JSON.stringify(data.videos);
    data.oldStudents = oldStudents;
    data.words = JSON.stringify(data.words);
    return request({
      url: `/subject/update`,
      method: "post",
      data,
    });
  },

  getParent() {
    return request({
      url: `/subject/getParent`,
      method: "get",
    });
  },

  save(data) {
    return request({
      url: `/subject/save`,
      method: "post",
      data,
    });
  },

  delete(id) {
    return request({
      url: `/subject/delete/${id}`,
      method: "post",
    });
  },

  updateTree(data) {
    return request({
      url: `/subject/updateTree`,
      method: "post",
      data,
    });
  },

  getUserAccountBySubjectId(subjectId) {
    return request({
      url: `/userRelationSubject/getUserAccountBySubjectId/${subjectId}`,
      method: "get",
    });
  },

  updateService(onService, id) {
    onService = onService ? 1 : 0;
    return request({
      url: `/subject/updateService/${onService}/${id}`,
      method: "put",
    });
  },

  updateNeedTest(needTest, id) {
    needTest = needTest ? 1 : 0;
    return request({
      url: `/subject/updateNeedTest/${needTest}/${id}`,
      method: "put",
    });
  },
};
